package org.pliers.canal.config;

import org.pliers.canal.client.CanalClientFactory;
import org.pliers.canal.properties.CanalProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(CanalProperties.class)
public class CanalBootstrapConfiguration {

    private CanalProperties properties;

    CanalBootstrapConfiguration(CanalProperties properties) {
        this.properties = properties;
    }

    @Bean
    public CanalSubscriberAnnotationBeanPostProcessor subscriberAnnotationBeanPostProcessor() {
        return new CanalSubscriberAnnotationBeanPostProcessor(defaultCanalClientFactory());
    }

    @Bean
    public CanalClientFactory defaultCanalClientFactory() {
        return new CanalClientFactory(properties);
    }

}
